package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import util.DBUtils;
import util.DataSourceManager;
import bean.Title;
import bean.Topic;

public class TitleDao {
	private QueryRunner runner = new QueryRunner(DataSourceManager.getSource());


	/**
	 * 获取促销快报列表
	 * @param pageNum 
	 * @param page 
	 * 
	 * @return
	 */
	public List<Title> getTitle() {
		List<Title> list = new ArrayList<Title>();
		Title title =null;
			//去操作 数据库 --- 写jdbc的代码 
			Connection conn = null;
			PreparedStatement stmt = null;
			ResultSet rs = null;
			try {
				conn = DBUtils.getConn();
				//查询 数据库 
				
				// select * from users where username=?
				// select * from users where email=?
				String sql ="select type,title from title";
				stmt = conn.prepareStatement(sql);
				
				
				rs = stmt.executeQuery();
				
				while(rs.next()){
					 title = new Title();
					//说明已经被占用了 
					 title.setType( rs.getString(1));
					 title.setTitle( rs.getString(2));
					list.add(title);
				}
				return list;
				
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}finally{
				
				//释放资源 
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			
		}

	
}
